unit InformarCartoes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBCtrls, ExtCtrls, StdCtrls, DB, DMCaixa;

type
  TfrmInformarCartao = class(TForm)
    dsCartoes: TDataSource;
    ListBox1: TListBox;
    Edit1: TEdit;
    procedure FormShow(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure ListBox1Exit(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmInformarCartao: TfrmInformarCartao;

implementation

{$R *.dfm}

procedure TfrmInformarCartao.FormShow(Sender: TObject);
begin
  ListBox1.Clear;
  dsCartoes.DataSet.Close;
  dsCartoes.DataSet.Open;

  while not dsCartoes.DataSet.Eof do begin
     ListBox1.Items.Add(dsCartoes.DataSet.FieldByName('Descricao').AsString);
     dsCartoes.DataSet.Next;
  end;
  listBox1.SetFocus;
  ListBox1.ItemIndex := 0;
end;


procedure TfrmInformarCartao.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if key=#13 then
    begin
      key:=#0;
      perform(WM_NextDLGCtl,0,0);
    end;
end;

procedure TfrmInformarCartao.ListBox1Exit(Sender: TObject);
var i : integer;
    desCartao : string;
begin
  for i := 0 to ListBox1.Count-1 do
  begin
    if (ListBox1.Selected[i]) then
    begin
      desCartao := trim(ListBox1.Items.Strings[i])  ;
    end;
  end;

  PreparaQuery('select CARTOES.CODIGOCARTAO, CARTOES.DESCRICAO FROM CARTOES WHERE CARTOES.DESCRICAO = '
                + chr(39) + desCartao + chr(39) + ';' ,
              dmcaixas.sqlq_geral)  ;

  ExecutaQuery(dmcaixas.sqlq_geral);
  with DMCaixas.sqlq_geral do
  begin
    frmFormasPagamento.lblCartao.Caption := FieldByName('CODIGOCARTAO').AsString;
  end;
  frmInformarCartao.Close;
  frmFormasPagamento.dbValor.SetFocus;
end;



procedure TfrmInformarCartao.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
    Action := caFree;
end;

end.
